package com.example.myapplication;

import android.content.Intent;
import android.os.Bundle;
import android.telephony.ClosedSubscriberGroupInfo;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;

import com.google.android.material.tabs.TabLayout;

import javax.security.auth.login.LoginException;

public class ScoringActivity extends AppCompatActivity {

    private static final String TAG = "Scoring";


    private TextView scoreATextView, scoreBTextView;
    private Button btnA1, btnA2, btnA3, btnB1, btnB2, btnB3, btnReset;
    private int scoreA = 0;
    private int scoreB = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_scoring);



        //获取传入数据
        Intent i = getIntent();
        float r1 = i.getFloatExtra("rate1",1.45f);
        float r2 = i.getFloatExtra("rate2",2.333f);
        String r3 = i.getStringExtra("rate3");

        Log.i(TAG,"onCreate:r1="+r1);
        Log.i(TAG,"onCreate:r2="+r2);
        Log.i(TAG,"onCreate:r3="+r3);








        scoreATextView = findViewById(R.id.score_a);
        scoreBTextView = findViewById(R.id.score_b);

        btnA1 = findViewById(R.id.btn_a1);
        btnA2 = findViewById(R.id.btn_a2);
        btnA3 = findViewById(R.id.btn_a3);

        btnB1 = findViewById(R.id.btn_b1);
        btnB2 = findViewById(R.id.btn_b2);
        btnB3 = findViewById(R.id.btn_b3);

        btnReset = findViewById(R.id.reset_button);


        btnA1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                updateScore(true, 1);
            }
        });

        btnA2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                updateScore(true, 2);
            }
        });

        btnA3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                updateScore(true, 3);
            }
        });


        btnB1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                updateScore(false, 1);
            }
        });

        btnB2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                updateScore(false, 2);
            }
        });

        btnB3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                updateScore(false, 3);
            }
        });


        btnReset.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                resetScores();
            }
        });
    }

    private void updateScore(boolean isTeamA, int points) {
        if (isTeamA) {
            scoreA += points;
            scoreATextView.setText(String.valueOf(scoreA));
        } else {
            scoreB += points;
            scoreBTextView.setText(String.valueOf(scoreB));
        }
    }

    private void resetScores() {
        scoreA = 0;
        scoreB = 0;
        scoreATextView.setText("0");
        scoreBTextView.setText("0");
    }
}